package com.lagou;

import redis.clients.jedis.Jedis;

/**
 * 借助Redis的Incr命令获取全局唯一ID（推荐）
 */
public class GlobalIdJedis {

    public static void main(String[] args) {
        Jedis jedis = new Jedis("127.0.0.1",6379);
        try {
            for (int i = 0; i < 10; i++) {
                long id = jedis.incr("id");
                System.out.println("序号: " + i + " 自增主键 = " + id);
            }
        } finally {
            if (null != jedis) {
                jedis.close();
            }
        }
    }
}
